cmake_minimum_required(VERSION 2.8)

set(PROJECT_NAME "cu.triangle")
project("${PROJECT_NAME}")

if (UNIX)
    set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/bin/linux")
    set(PLATFORM_SRC GPUhelper/gh.linux.c)
    set(PLATFORM_LIB X11 GL)
    set(CMAKE_C_FLAGS "-Wall -msse2 -O2")
elseif (WIN32)
    set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/bin")
    add_definitions(-D_CRT_SECURE_NO_WARNINGS)
    add_definitions(-DGLEW_STATIC)
    set(PLATFORM_SRC GPUhelper/gh.windows.c)
    set(PLATFORM_LIB OpenGL32)
    set(CONSOLE_SYS WIN32)
endif ()

# search for CUDA in standard paths
find_path(CUDA_INCLUDE_DIR cuda.h /usr/local/cuda/include "C:/Program Files (x86)/NVIDIA GPU Computing Toolkit/CUDA/v4.0/include")
find_library(CUDA_LIBRARY cuda "C:/Program Files (x86)/NVIDIA GPU Computing Toolkit/CUDA/v4.0/lib/Win32")
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(cuda DEFAULT_MSG CUDA_INCLUDE_DIR CUDA_LIBRARY)

set(SRC
    app.c
    GPUhelper/gh.h GPUhelper/gh.c GPUhelper/gh.app.h GPUhelper/gh.math.h GPUhelper/gh.math.c GPUhelper/gh.cu.h GPUhelper/gh.cu.c GPUhelper/gh.ptx.h
    GLEW/glew.c)

include_directories(./ GPUhelper "${CUDA_INCLUDE_DIR}")
add_executable("${PROJECT_NAME}" ${CONSOLE_SYS} ${SRC} ${PLATFORM_SRC})
target_link_libraries("${PROJECT_NAME}" ${PLATFORM_LIB} "${CUDA_LIBRARY}")